import threading
import time
list = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
class MyThread(threading.Thread):
    def __init__(self, threadId, name, counter):
        threading.Thread.__init__(self)
        self.threadId = threadId
        self.name = name
        self.counter = counter
    def run(self):
        print("开始线程：", self.name)
        threadLock.acquire()
        print_time(self.name, self.counter, list.__len__())
        threadLock.release()
    def __del__(self):
        print(self.name, "线程结束")
def print_time(threadName, delay, counter):
    while counter:
        time.sleep(delay)
        list[counter-1] += 1
        print("%s:%s" % (threadName, time.ctime(time.time())))
        counter -= 1
threadLock = threading.Lock()
threads = []

thread1 = MyThread(1, "Thread-1", 1)
thread2 = MyThread(2, "Thread-2", 2)

thread1.start()
thread2.start()

threads.append(thread1)
threads.append(thread2)
# for t in threads:
#    t.join()
print("主线程结束！")


